<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>flutter客户端通信</title>
</head>
<body>
  <div class="container">
    <div class="title">
      <button>改变标题</button>
    </div>
    <div class="login">
      <button>登录</button>
      我的id是：<span></span>
    </div>

  </div>
  <script src="https://s-test.kcimg.cn/utils/utils-min.2.0.0.js"></script>
  <script>
    var uid = ''
    function showId() {
      var UA = navigator.userAgent
      uid = parseInt(UA.match(/USERID[^\s]+/)
        ? UA.match(/USERID[^\s]+/)[0].substr(7)
        : 0)
      document.querySelector('.login span').innerHTML = uid
    }
    function onLoginCallback(data) {
      var res = typeof data === 'object' ? data : JSON.parse(data)
      if (res.status) {
        if (res.data.accountId) {
          uid = res.data.accountId
        } else {
          const UA = navigator.userAgent
          uid = UA.match(/USERID[^\s]+/) ? UA.match(/USERID[^\s]+/)[0].substr(7) : '0'
        }
        //登录成功去干什么操作
        showId()
      }
    }
      document.querySelector('.login button').addEventListener('click', function () {
      if (!uid) {
        // 注册登录回调
        window.onLoginCallback = onLoginCallback
        //吊起app登录方法
        window.callNativeMethod('onLogin', {})
      }
    })
    document.querySelector('.title button').addEventListener('click', function () {
      callNativeMethod('onChangeWebTitle', {
        changeWebTitle: '我是首页'
      })
    })
  </script>
</body>
</html>